package cn.yh.register.hosp.controller;

import cn.yh.register.common.result.Result;
import cn.yh.register.hosp.service.HospitalService;
import cn.yh.register.model.hosp.Hospital;
import cn.yh.register.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

//@CrossOrigin
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation("分页条件查询医院")
    @GetMapping("/{page}/{limit}")
    public Result< Page<Hospital>> findByPage(@PathVariable Integer page,
                                @PathVariable Integer limit,
                                HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pageList = hospitalService.findPageList(hospitalQueryVo, page, limit);
        return Result.ok(pageList);
    }

    @ApiOperation(value = "查询医院数据详情")
    @GetMapping("/show/{id}")
    public Result<Map<String, Object>> show(@PathVariable String id){
        Map<String, Object> map = hospitalService.getById(id);
        return Result.ok(map);
    }

    @ApiOperation(value = "更新上线状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public Result<?> lock(
            @ApiParam(name = "id", value = "医院id", required = true)
            @PathVariable("id") String id,
            @ApiParam(name = "status", value = "状态（0：未上线 1：已上线）", required = true)
            @PathVariable("status") Integer status){
        hospitalService.updateStatus(id, status);
        return Result.ok();
    }



}
